import csv
from xml.dom import minidom

# 读取txt文件
user_file = open('C:\\wksPy\\user_info.txt', 'r')
lines = user_file.readlines()
user_file.close()

for line in lines:
    username = line.split(',')[0]
    password = line.split(',')[1]
    print(username, password)

# 读取CSV
data = csv.reader(open('C:\\wksPy\\info.csv', 'r'))
for user in data:
    print(user)
    print('邮箱地址：', user[1])

# 读取XML文件
dom = minidom.parse('C:\\wksPy\\info.xml')
root = dom.documentElement
print(root.nodeName)
print(root.nodeType)
print(root.ELEMENT_NODE)
# xml获取到标签
tagname = root.getElementsByTagName('browser')
print(tagname[0].tagName)
# 获取xml标签的属性值
logins = root.getElementsByTagName('login')
for login in logins:
    username = login.getAttribute('username')
    password = login.getAttribute('password')
    print(username, password)
# 获取XML标签对之间的数据
provinces = dom.getElementsByTagName('province')
citys = dom.getElementsByTagName('city')
p2 = provinces[0].firstChild.data
print(p2)
